﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Windows.Navigation;
using System.IO;
using System.Text;

namespace TripleTriad
{
    public partial class MainPage : PhoneApplicationPage
    {

        private static string key = "user";

        //storage dell'applicazione
        private static IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }//costruttore

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!(appSettings.Contains(key)))//non c'è un account
            {
                NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));//cambio della pagina
            }
            if (NavigationService.CanGoBack)
                NavigationService.RemoveBackEntry();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)//ho appena fatto il login
                NavigationService.RemoveBackEntry();
        }

        private void random_match_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/CreaMazzo.xaml", UriKind.Relative));
        }

        private void friends_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Amici.xaml", UriKind.Relative));
        }

        private void my_cards_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MieCarte.xaml", UriKind.Relative));
        }

        private void rules_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Regole.xaml", UriKind.Relative));
        }

        private void market_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Market.xaml", UriKind.Relative));
        }

        private void info_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Info.xaml", UriKind.Relative));
        }

        private void credits_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Riconoscimenti.xaml", UriKind.Relative));
        }

        private void logout_Click(object sender, RoutedEventArgs e)
        {
            //cancello tutto
            appSettings.Clear();
            DataSaver<Utente> myUserDataSaver = new DataSaver<Utente>();
            myUserDataSaver.DeleteMyData("UserObject");
            NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
            
        }
    }
}